﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="workflow.js.aspx.cs" Inherits="ASB.CC.Web.WorkflowJS" %>


<%--缓存11天--%>
<%@ OutputCache Duration="999999" VaryByParam="none" %>

<%@ Import Namespace="global::Resources" %>


function FreshFieldNumber()
{
    var current = 1;
    $(".title_list:visible").each(function(index){
        var txt = $.trim($(this).text());
        var begin = txt.indexOf('.');
        if(begin > 2){
            begin = -1;
        }
        var content  = txt.substring(begin + 1,txt.length);
        $(this).text(current.toString() + '.' + content);
        current++;
        
    });
}


<%--全球化文字以及workflow共享辅助方法--%>
$(function(){

    <%--以下定义一些基础方法--%>
    var SetToolTip = function(selector, value){
        $(selector).attr("title", value);
    };

    var SetTextToolTip = function(selector, text, tooltip){
        $(selector).attr("title", tooltip).val(text);
    };
    
    <%--以下是设置 Workflow Button 的Text和Title--%> 
    SetTextToolTip("#workflow-close", "<%=GlobalButton.Close%>", "<%=GlobalButton.CloseTips%>");
    SetTextToolTip("#workflow-log", "<%=GlobalButton.Log%>", "<%=GlobalButton.LogTips%>");
    SetTextToolTip(".workflow-upload", "<%=GlobalButton.Upload%>", "<%=GlobalButton.UploadTips%>");
 
    
    <%--以下是DatePicker--%> 
    $(".datepicker").datepicker({
        changeYear: true,
        changeMonth: true,
        yearRange: 'c-40:c+10',
        changeYear: true,
        showOn: "button",
        buttonImage: "../images/calendar.gif",
        buttonImageOnly: true,
        buttonText: 'Open Calendar (打开日历)'
    }).attr("readonly", "true");
    
    $(".datepicker1").datepicker({
        changeYear: true,
        changeMonth: true,
        yearRange: 'c-40:c+10',
        changeYear: true,
        showOn: "button",
        buttonImage: "../images/calendar.gif",
        buttonImageOnly: true,
        buttonText: 'Open Calendar (打开日历)',
        minDate: '+0d'
    }).attr("readonly", "true");
    

    
    <%--以下是追加 workflow-log 代码--%>
    $("#workflow-log").appendTo(".action_layer").first().
        addClass("btn").
        each(function(){
        
            var appID = $.query.get('AppID');
            if(appID == '')
                appID = $.query.get('appid')
                
            if(appID != '')
                $(this).
                    show().
                    bind("click", function() {
                        var url = "Log.aspx?AppID=" + appID;
                        window.open(url, "", "height=640,width=800,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,resizable=yes");
                    });
        });
        
    <%--以下是追加 workflow-close 代码--%>
    $("#workflow-close").appendTo(".action_layer").first().
        addClass("btn").
        each(function(){
            if($(".app-close").length == 0)
                $(this).
                    show().
                    bind("click", function() {
                        if(confirm("Are you sure to close the window?") == true)
                            SimpleCloseWindow();
                        else
                            return false;
                    });
        });
        
   <%--以下是调整图章代码--%>
 <%--   $("#workflow-stamp-header").appendTo("#workflow-stamp-container");
    $(".workflow-stamp-content").parent().parent().parent().parent().appendTo("#workflow-stamp-container");--%>    
      <%--根据query 决定是否显示图章，和是否显示打印和导出--%> 
      var flow = $.query.get('FlowID');
        if(flow == '' || flow == true)
        {
		    flow = $.query.get('flowid');
		    if(flow == '' || flow == true)
		    {
            		    $("#workflow-stamp-container").hide();
            		    $(".workflow-print").hide();
		    }
        }
       var type = $.query.get('PDType');
       if(type == '' || type == true || type == 'EV' || type == 'CR')
       {
            $(".workflow-export").hide();
       }
       else
       {
            if(flow == '' || flow == true)
            {
               $(".workflow-export").hide(); 
            }
       }


    <%--调整窗口大小--%>
<%--    try{
        window.resizeTo(1200, 750);
    }
    catch(e){
    }--%>
    
    <%--workflow全局调试信息，上线时移除此代码--%>
    $(".workflow-debug").append("<span>"+window.location.href+"</span>");
        
    <%--为ie6全局添加input-text样式--%>
    $("input[type=text]").addClass("input_text_225");
    
    
    <%--workflow窗口unload事件--%>
    $(window).bind("beforeunload", function(){
     <%--   $("select").hide();--%>
        $("#dialog-message").dialog({
		    modal: true
	    });   
    });
    
    
    <%--每当关闭或者重新加载页面时刷新父窗口--%>
<%--    $(window).unload(function() {
        if(window.opener && !window.opener.closed)
            <%--如果使用window.opener.location.reload()父窗口会重新post数据，
            那样会弹出一个retry对话框，暂时没有办法解决！
            try{
                window.opener.location.reload();
            }catch(e){
            }
    }); --%>
  

    
    <%--workaround for EV print, 因为EV没有print页面--%>
    $(".workflow-print").each(function(){
            $(this).
                attr("onclick", "").
                bind("click", function(){
                    window.print();
                });
    });
    
    <%--隐藏所有copy按钮--%>
    $(".workflow-copy").hide();
    
    <%--将Application No转移到workflow-top-container--%>
    $("div.appno-position1").appendTo("#workflow-top-container");
    
    <%-- 隐藏CR中的MKD展厅链接 --%>
    $("div#CR-MKD").hide();
    
    
    <%-- 日期比较全局控制 --%> 
    $(".date-cmp").bind("change", function () {

        var targetclass;
        var targetflag;
        var classes = $(this).attr('class').split(' ');
        for (i = 0; i < classes.length; i++) {
            if (classes[i].indexOf('date-min') == 0) {
                targetclass = 'date-max' + classes[i].substring(8, classes[i].length);
                targetflag = 'max';
                break;
            }
            else if (classes[i].indexOf('date-max') == 0) {
                targetclass = 'date-min' + classes[i].substring(8, classes[i].length);
                targetflag = 'min';
                break;
            }
        }

        if (targetclass != null) {
            var target = $(".date-cmp." + targetclass).first();
            var targetvalue = target.val();
            if (targetvalue != '') {
                if (targetflag == 'max') {
                 var dt1=new Date(Date.parse(targetvalue));
                 var dt2=new Date(Date.parse($(this).val()));
                    if (dt1< dt2) {
                        var mintitle = $(this).parent().prev().text();
                        var maxtitle = target.parent().prev().text();
                        alert('[' + mintitle + ']' + ' could not be later than ' + '[' + maxtitle+ ']');
                        $(this).val('');
                    }
                }
                else //for targetflag == 'min'
                {
                    var dt1=new Date(Date.parse(targetvalue));
                    var dt2=new Date(Date.parse($(this).val()));
                    if (dt1>dt2) {
                        var maxtitle = $(this).parent().prev().text();
                        var mintitle = target.parent().prev().text();
                        alert('[' + maxtitle + ']' + ' could not be earlier than '+ '[' + mintitle+ ']');
                        $(this).val('');
                    }
                }
            }
        }
    });
    
    
    <%-- CR -B remove in AppNo --%> 
    var appNoSpan = $(".appno-position1 span");
    if(appNoSpan != null){
        var appNo = appNoSpan.text();
        if(appNo != ''){
            appNo = appNo.replace(/Application No:/,"");
            <%-- getCRNonB is in common.js --%>
            appNoSpan.text('Application No:' + getCRNonB($.trim(appNo)));
            appNoSpan.attr('style','font-weight:bold;');
        }
    }
    
    FreshFieldNumber();
    

});




